package com.proyemp.pruebaEasyService;

import java.util.ArrayList;
import java.util.List;

import com.proyemp.instancia.AbstractContract;
import com.proyemp.instancia.AbstractSolver;
import com.proyemp.instancia.Result;
import com.proyemp.objetos.parameters.prueba.EasyParameter;
import com.proyemp.objetos.presentacion.prueba.Product;
import com.proyemp.objetos.responses.prueba.EasyResponse;



public class SolverEasyService extends AbstractSolver {

	EasyParameter parametersX = null;
	
	/*
	 *
	 */
	//@Override
	public void validar() {

	}
	
	/* 
	 * 
	 */
	//@Override
	public void inicializar(List contrLista) {
		AbstractContract contrato = (AbstractContract)contrLista.get(0);
		List parametro = contrato.getParameters();
		parametersX = (EasyParameter)parametro.get(0);
	}

	/* 
	 * 
	 */
	//@Override
	public Result resolver() {
		Result resultado = new Result();
        EasyResponse responseX= new EasyResponse();
 
        // si parametros vacios devuelve error, error if empty parameters 
        if (parametersX==null || parametersX.getClientID()==null || parametersX.getClientID().length()<=0){ 
            responseX.setErrorCode(10001); 
            responseX.setErrorDescription("Debe indicar ID Cliente.");
        } else {
        	//crea lista productos del cliente, fill the client product list 
            //para ejemplo en duro, for the example fixed data 
            Product[] productsListX= new Product[5]; 
            
            Product productX= new Product(); 
            productX.setBarCode("0001"); 
            productX.setName("Tarjeta Visa, Visa Credit Card"); 
            productsListX[0]= productX; 
     
            productX= new Product(); 
            productX.setBarCode("0002"); 
            productX.setName("aaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaa" +
            		"aaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa" + 
            		"aaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa"); 
            productsListX[1]= productX; 
            
            productX= new Product(); 
            productX.setBarCode("0003"); 
            productX.setName("ajoyin"); 
            productsListX[2]= productX; 
            
            productX= new Product(); 
            productX.setBarCode("0004"); 
            productX.setName("no shieee"); 
            productsListX[3]= productX; 
            
            productX= new Product(); 
            productX.setBarCode("0005"); 
            productX.setName("tufli "); 
            productsListX[4]= productX; 
            
     
            //respuesta exitosa, sucessfull response 
            responseX.setErrorCode(0); 
            responseX.setErrorDescription("Consulta Banco Exitosa, Succesfull Bank Query"); 
            responseX.setProducts(productsListX); 
        }
        List enviar = new ArrayList();
        enviar.add(responseX);
        resultado.setDatos(enviar);
        return resultado;
	}

}
